﻿using SketchUpAPI.NET.Enums;
using SketchUpAPI.NET.SketchUp.Exception;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SketchUpAPI.NET.Objects
{
    public class TypedValue : ObjectBase
    {
        #region API 函数
        /// <summary>
        /// 创建一个SUTypedValue
        /// </summary>
        /// <param name="typedValue"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUTypedValueCreate(out IntPtr typedValue);

        /// <summary>
        /// 获取整型值
        /// </summary>
        /// <param name="typedValue"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUTypedValueGetInt32(IntPtr typedValue, out int value);

        /// <summary>
        /// 设置整型值
        /// </summary>
        /// <param name="typedValue"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUTypedValueSetInt32(IntPtr typedValue, int value);

        /// <summary>
        /// 获取双精度浮点数值
        /// </summary>
        /// <param name="typedValue"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUTypedValueGetDouble(IntPtr typedValue, out double value);

        /// <summary>
        /// 获取布尔型值
        /// </summary>
        /// <param name="typedValue"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUTypedValueGetBool(IntPtr typedValue, out bool value);
        #endregion

        public TypedValue()
        {
            SketchUpExceptionHelper.ThrowSUResult(SUTypedValueCreate(out Id));
        }

        internal TypedValue(IntPtr id) => Id = id;

        /// <summary>
        /// 获取整型值
        /// </summary>
        /// <returns></returns>
        public int GetInt32()
        {
            SketchUpExceptionHelper.ThrowSUResult(SUTypedValueGetInt32(Id, out int value));
            return value;
        }

        /// <summary>
        /// 获取双精度浮点数值
        /// </summary>
        /// <returns></returns>
        public double GetDouble()
        {
            SketchUpExceptionHelper.ThrowSUResult(SUTypedValueGetDouble(Id, out double value));
            return value;
        }

        /// <summary>
        /// 获取布尔值
        /// </summary>
        /// <returns></returns>
        public bool GetBoolean()
        {
            SketchUpExceptionHelper.ThrowSUResult(SUTypedValueGetBool(Id, out bool value));
            return value;
        }

        /// <summary>
        /// 设置一个整型值
        /// </summary>
        /// <param name="value"></param>
        public void Set(int value)
        {
            SketchUpExceptionHelper.ThrowSUResult(SUTypedValueSetInt32(Id, value));
        }

        /// <summary>
        /// 设置一个双精度浮点数
        /// </summary>
        /// <param name="value"></param>
        public void Set(double value)
        {

        }

        /// <summary>
        /// 设置一个布尔值
        /// </summary>
        /// <param name="value"></param>
        public void Set(bool value)
        {

        }

        /// <summary>
        /// 创建一个 TypedValue
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static TypedValue Create(int value)
        {
            TypedValue t = new TypedValue();
            t.Set(value);
            return t;
        }
    }
}